import 'package:BeeApp/LoginAndRegister/LoginPage.dart';
import 'package:BeeApp/MainPage/MainToolPage.dart';
import 'package:flutter/material.dart';

class ChooseUserPage extends StatefulWidget {
  ChooseUserPage({Key key}) : super(key: key);

  @override
  _ChooseUserPageState createState() => _ChooseUserPageState();
}

class _ChooseUserPageState extends State<ChooseUserPage> {
  int chooseType;
  @override
  void initState() {
    super.initState();
    chooseType = 1;
    setData("AppType", chooseType.toString());
    print("------" + getData("AppType"));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("选择角色"),
        elevation: 0,
        centerTitle: true,
      ),
      body: ListView(
        children: <Widget>[
          Container(
            padding: EdgeInsets.all(20),
            child: Text(
              "请选择您想要成为的角色",
              style: TextStyle(
                color: Color(0xff999999),
                fontSize: setFontSize(36),
                fontWeight: FontWeight.w500,
              ),
            ),
          ),
          SizedBox(height: setHeight(90)),
          chooseView(),
          SizedBox(height: setHeight(120)),
          Container(
            padding: EdgeInsets.only(left: 16, right: 16),
            child: loginView(),
          ),
        ],
      ),
    );
  }

  Widget chooseView() {
    return Container(
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: <Widget>[
          inkWellView("MainLogoImage", "货主", 1),
          inkWellView("MainLogoImage", "车主", 2),
        ],
      ),
    );
  }

  Widget inkWellView(String imageStr, String title, int index) {
    return InkWell(
      child: Container(
        width: setWidth(260),
        height: setHeight(300),
        // padding: EdgeInsets.all(setHeight(30)),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.all(Radius.circular(15)),
          boxShadow: [
            BoxShadow(
                color: Color.fromRGBO(0, 0, 0, 0.16),
                offset: Offset(0.0, 6.0), //阴影xy轴偏移量
                blurRadius: 6.0, //阴影模糊程度
                spreadRadius: 1.0 //阴影扩散程度
                )
          ],
        ),
        child: Column(children: <Widget>[
          SizedBox(height: setHeight(30)),
          Image.asset(
            "images/ChooseUserImage0$index.png",
            height: setHeight(123),
            width: setWidth(134),
          ),
          SizedBox(height: 8),
          Text(
            title,
            style: TextStyle(
              color: Color(0xFF333333),
              fontSize: setFontSize(36),
            ),
          ),
          SizedBox(height: 8),
          Image.asset(
            chooseType == index
                ? "images/MainSelectImage.png"
                : "images/MainNoneImage.png",
            height: setHeight(40),
          )
        ]),
      ),
      onTap: () {
        setState(() {
          chooseType = index;
        });
      },
    );
  }

  Widget loginView() {
    return InkWell(
      child: Container(
        alignment: Alignment.center,
        height: setHeight(100),
        decoration: BoxDecoration(
          color: maincolor,
          borderRadius: BorderRadius.all(
            Radius.circular(setHeight(10)),
          ),
        ),
        child: Text(
          "下一步",
          style: TextStyle(color: Colors.white, fontSize: setFontSize(34)),
        ),
      ),
      onTap: () {
        setData("AppType", chooseType.toString());
        Navigator.push(
            context, MaterialPageRoute(builder: (context) => LoginPage()));
      },
    );
  }
}
